//
//  BaseViewController.m
//  BuSuanZi
//
//  Created by HZ on 2025/2/15.
//

#import "BSZBaseViewController.h"

@interface BSZBaseViewController ()

@property (nonatomic, strong) NSArray *idleAry;
@property (nonatomic, strong) NSArray *pullAry;
@property (nonatomic, strong) NSArray *refreshAry;

@end

@implementation BSZBaseViewController

- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (void)alpaNavBar{
    self.zdyNavBar.backgroundColor = ClearColor;
    self.zdyNavBar.statusBar.backgroundColor = ClearColor;
    self.zdyNavBar.navigationBar.backgroundColor = ClearColor;
    self.zdyNavBar.bottomLineView.backgroundColor = ClearColor;
}

#pragma mark --添加下拉刷新
- (void)addNormalHeaderRefresh:(UIScrollView *)tableView{
//    _header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefreshAction)];
    
    NSArray *idleImages = [NSArray arrayWithObject:[UIImage imageNamed:@"catloading_one"]];
//    [NSArray arrayWithObjects:[UIImage imageNamed:@"catloading_one"],[UIImage imageNamed:@"catloading_two"],[UIImage imageNamed:@"catloading_three"],[UIImage imageNamed:@"catloading_four"], nil];
    NSArray *pullingImages = [NSArray arrayWithObject:[UIImage imageNamed:@"catloading_one"]];
    NSArray *refreshingImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"catloading_one"],[UIImage imageNamed:@"catloading_two"],[UIImage imageNamed:@"catloading_three"],[UIImage imageNamed:@"catloading_four"], nil];
    
    _header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefreshAction)];
    
    // 隐藏更新时间
    _header.lastUpdatedTimeLabel.hidden = YES;
    // 隐藏刷新状态
    _header.stateLabel.hidden = YES;
    
    //1.设置普通状态的动画图片
    [_header setImages:idleImages forState:MJRefreshStateIdle];
    //2.设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [_header setImages:pullingImages forState:MJRefreshStatePulling];
    //3.设置正在刷新状态的动画图片
    [_header setImages:refreshingImages forState:MJRefreshStateRefreshing];
    
    tableView.mj_header = _header;
}
//- (void)addGifRefresh:(UITableView *)tableView{
    /**动画下拉*/
    //    _header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefreshAction)];
    //    [_header setImages:self.idleAry forState:MJRefreshStateIdle];
    //    [_header setImages:self.pullAry forState:MJRefreshStatePulling];
    //    [_header setImages:self.refreshAry forState:MJRefreshStateRefreshing];
    //    _header.lastUpdatedTimeLabel.hidden = YES;
    //    _header.stateLabel.hidden = YES;
//        tableView.mj_header = _header;
//}

#pragma mark --添加上拉更多
- (void)addNormalFooterRefresh:(UIScrollView *)tableView{
//    _footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefreshAction)];
//    _footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefreshAction)];
    
    _footer = [MJRefreshAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefreshAction)];
    tableView.mj_footer = _footer;
}
#pragma mark -- 下拉执行方法
- (void)headerRefreshAction{
    
}
#pragma mark -- 上拉执行方法
- (void)footerRefreshAction{
    
}

#pragma mark --开始刷新
- (void)begainRefresh{
    [_header beginRefreshing];
}
#pragma mark --结束刷新
- (void)endRefresh{
    [_header endRefreshing];
    [_footer endRefreshing];
}

- (NSArray *)idleAry{
    if (!_idleAry) {
        _idleAry = @[[UIImage imageNamed:@"bdj_mj_refresh_1"],[UIImage imageNamed:@"bdj_mj_refresh_2"],[UIImage imageNamed:@"bdj_mj_refresh_3"],[UIImage imageNamed:@"bdj_mj_refresh_4"]];
    }
    return _idleAry;
}
- (NSArray *)pullAry{
    if (!_pullAry) {
        _pullAry = @[[UIImage imageNamed:@"bdj_mj_refresh_1"],[UIImage imageNamed:@"bdj_mj_refresh_2"],[UIImage imageNamed:@"bdj_mj_refresh_3"],[UIImage imageNamed:@"bdj_mj_refresh_4"]];
    }
    return _pullAry;
}
- (NSArray *)refreshAry{
    if (!_refreshAry) {
        _refreshAry = @[[UIImage imageNamed:@"bdj_mj_refresh_1"],[UIImage imageNamed:@"bdj_mj_refresh_2"],[UIImage imageNamed:@"bdj_mj_refresh_3"],[UIImage imageNamed:@"bdj_mj_refresh_4"]];
    }
    return _refreshAry;
}

#pragma make -----懒加载
- (UITableView *)dataTableView{
    if (!_dataTableView) {
        _dataTableView = [[UITableView alloc]init];
        _dataTableView.backgroundColor = [UIColor whiteColor];
        _dataTableView.delegate = self;
        _dataTableView.dataSource = self;
        _dataTableView.separatorInset = UIEdgeInsetsZero;
        _dataTableView.separatorColor = [UIColor lightGrayColor];
        _dataTableView.showsVerticalScrollIndicator = NO;
        _dataTableView.showsHorizontalScrollIndicator = NO;
        if (@available(iOS 11.0, *)) {
            _dataTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else if (@available(iOS 15.0, *)) {
            _dataTableView.sectionHeaderTopPadding = 0;
        }
        _dataTableView.estimatedRowHeight = 0;
        _dataTableView.estimatedSectionFooterHeight = 0;
        _dataTableView.estimatedSectionHeaderHeight = 0;
        _dataTableView.tableFooterView = [[UIView alloc]init];
    }
    return _dataTableView;
}

- (NSMutableArray *)dataArry{
    if (!_dataArry) {
        _dataArry = [[NSMutableArray alloc]initWithCapacity:0];
    }
    return _dataArry;
}

- (BSZNavigationBar *)zdyNavBar{
    if (!_zdyNavBar) {
        _zdyNavBar = [[BSZNavigationBar alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, STATUS_BAR_HEIGHT+NAV_BAR_HEIGHT)];
//        _zdyNavBar.hidden = YES;
    }
    return _zdyNavBar;
}

- (UIView *)containerView{
    if (!_containerView) {
        _containerView = [[UIView alloc]initWithFrame:CGRectMake(0, NAV_BAR_HEIGHT+STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-STATUS_BAR_HEIGHT-NAV_BAR_HEIGHT)];
//        if (kDevice_Is_iPhoneX) {
//            _containerView.frame = CGRectMake(0, NAV_BAR_HEIGHT+STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-STATUS_BAR_HEIGHT-NAV_BAR_HEIGHT-TABBAR_BOTTOM_HEIGHT);
//        }
        _containerView.backgroundColor = ColdLightGrayColor;
        _containerView.hidden = YES;
    }
    return _containerView;
}


//- (void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//    [self.navigationController setNavigationBarHidden:YES animated:animated];
//}
//
//- (void)viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:animated];
//    [self.navigationController setNavigationBarHidden:NO animated:animated];
//}

+ (void)load{
    if (@available(iOS 11.0, *)) {
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    }else{
//        self.automaticallyAdjustsScrollViewInsets = NO; (ios 7.0)
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.currentPage = 1;
    [self stepUI];
    // 所有界面隐藏导航栏,用自定义的导航栏代替
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = ColdLightGrayColor;
    
    [self.view addSubview:self.zdyNavBar];
    [self.view addSubview:self.containerView];
    
//    self.containerView.frame = CGRectMake(0, NAV_BAR_HEIGHT+STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-STATUS_BAR_HEIGHT-NAV_BAR_HEIGHT);
//    if (kDevice_Is_iPhoneX) {
//        self.containerView.frame = CGRectMake(0, NAV_BAR_HEIGHT+STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-STATUS_BAR_HEIGHT-NAV_BAR_HEIGHT-TABBAR_BOTTOM_HEIGHT);
//    }
//    self.containerView.backgroundColor = ColdLightGrayColor;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)stepUI{
    self.zdyNavBar.leftMenuButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.zdyNavBar.leftMenuButton setImage:[UIImage imageNamed:@"qm_back"] forState:UIControlStateNormal];
    [self.zdyNavBar.leftMenuButton addTarget:self action:@selector(runBack) forControlEvents:UIControlEventTouchUpInside];
}

//返回
- (void)runBack{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark --提示
- (void)alertTitle:(NSDictionary *)dictionary leftHandler:(void(^)(void))leftHandler rightHandler:(void(^)(void))rightHandler{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[dictionary objectForKey:@"title"] message:[dictionary objectForKey:@"content"] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[dictionary objectForKey:@"leftTitle"] style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        leftHandler();
    }];
    UIAlertAction *commitAction = [UIAlertAction actionWithTitle:[dictionary objectForKey:@"rightTitle"] style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        rightHandler();
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:commitAction];
    [self presentViewController:alertController animated:YES completion:^{
    }];
}

#pragma make ---------- UITableViewDataSource代理方法
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    return nil;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}


@end
